package com.greatpengcode.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.greatpengcode.dao.DepartmentDao;
import com.greatpengcode.dao.EmployeeDao;
import com.greatpengcode.pojo.Employee;
import com.greatpengcode.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeDao employeeDao;
    @Override
    public PageInfo<Employee> getAllEmployee(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Employee> employees = employeeDao.getAllEmployee();
        PageInfo<Employee> employeePageInfo = new PageInfo<>(employees,pageSize);
        return employeePageInfo;
    }

    @Override
    public Employee getEmployeeById(Integer id) {
        Employee employee = employeeDao.getEmployeeById(id);
        return employee;
    }

    @Override
    public int addEmployee(Employee employee) {
        int result = employeeDao.addEmployee(employee);
        return result;
    }

    @Override
    public int updateEmployee(Employee employee) {
        int result = employeeDao.updateEmployee(employee);
        return result;
    }

    @Override
    public int deleteEmployee(Integer id) {
        int result = employeeDao.deleteEmployee(id);
        return result;
    }
}
